package com.yiduo.outpost.core.web.exception;

import com.yiduo.outpost.core.model.exception.RestException;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * @author yanwen
 */
public class RestExceptionTranslator implements ExceptionTranslator {

    @Override
    public boolean support(Throwable error) {
        return error instanceof RestException;
    }

    @Override
    public String translateException(Throwable error, MessageSource messageSource) {
        Object[] args = ((RestException) error).getArgs();
        return messageSource.getMessage(error.getMessage(), args, error.getMessage(), LocaleContextHolder.getLocale());
    }
}
